<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/extjs/include/all.jsp"%>
<title></title>
<script type="text/javascript">
	Ext.onReady(function(){
		var resultWidth = Ext.get("process-grid").getWidth();
		var userId = '${__SATURN_AUTORITY_USER__.id}';
		var process_instance_id = <%=request.getParameter("process_instance_id")%>;
		var store = new Ext.data.JsonStore({
		    url: '${pageContext.request.contextPath}/edu.ccut.saturn.workflow.manager::/queryModule/action/QueryActivityList.action',
		    root: 'result',
		    totalProperty:'count',
		    fields: [
	               {name: 'activity_instance_id', mapping: 'activity_instance_id'},
	               {name: 'name', mapping: 'name'},
	               {name: 'type', mapping: 'type'},
	               {name: 'state', mapping: 'state'}, 
	               {name: 'is_timeout', mapping: 'is_timeout'}, 
	               {name: 'process_instance_id', mapping: 'process_instance_id'}, 
		    	   {name: 'start_time', mapping: 'start_time'},
	               {name: 'end_time', mapping: 'end_time'}
	           ]
		});
		
	  
	    var grid = new Ext.grid.GridPanel({
		    frame:true,
		    bodyStyle:'width:100%',
		    title:'活动列表',
       	    store: store,
	        columns: [	 
	            {header: "活动ID", width: resultWidth*0.06, dataIndex: 'activity_instance_id', sortable: true},
	            {header: "活动名称", width:resultWidth*0.14, dataIndex: 'name', sortable: true,renderer:showActInfo},
	            {header: "活动类型", width:resultWidth*0.08, dataIndex: 'type', sortable: true,renderer:showType},
	            {header: "当前状态", width:resultWidth*0.08, dataIndex: 'state', sortable: true,renderer:showState},
	            {header: "是否超时", width:resultWidth*0.08, dataIndex: 'is_timeout', sortable: true,renderer:timeout},
	            {header: "流程实例ID", width:resultWidth*0.08, dataIndex: 'process_instance_id', sortable: true},
	            {header: "活动开始时间", width:resultWidth*0.15, dataIndex: 'start_time', sortable: true},
	            {header: "活动结束时间", width:resultWidth*0.15, dataIndex: 'end_time', sortable: true},
	            {header: "操作", width:resultWidth*0.2, dataIndex: 'activity_instance_id', sortable: true,renderer:showOp}
	        ],
	        renderTo:'process-grid',
	        height:500,
	        frame:true,
	        loadMask: {msg:'正在加载数据，请稍侯……'}, 
	        tbar:new Array(
			   new Ext.Toolbar.Button({
						   text:'返回',
						   xtype:"button" ,
						   tooltip:"返回上一个页面" ,
						   handler: goBack,
						   scope :this})),
	        bbar: new Ext.PagingToolbar({ 
		            pageSize: 20, 
		            store: store, 
		            displayInfo: true, 
		            displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
		            emptyMsg: "没有数据显示" 
		    }) 
    });
   	store.load({params: {start:0,limit:20,process_instance_id:process_instance_id}});
   	
   	store.on('beforeload',function(){
	    Ext.apply(this.baseParams,{process_instance_id:process_instance_id});
    });
    
   	function timeout(value){
		if(value=='Y'){
			return "是";
		}else{
			return "否";
		}
	}
   	function showOp(value,cellmeta,record){	
   	      return "<a href='javascript:showWorkitem("+value+")'>活动中的工作项</a>"
	}	
	
	function showActInfo(value,cellmeta,record){	
   	      return "<a href='javascript:showActivityInfo("+record.data["activity_instance_id"]+")'>"+value+"</a>";
	}	
	
	function showState(value){
		if(value=='2')
			return "运行";
		if(value=='7')
			return "完成";
	}
	
	function goBack(){	
		window.history.back();
	}
	
});

	function showType(value){
		if(value=='start'){
			return "开始活动";
		}
		if(value=='man'){
			return "人工活动";
		}
		if(value=='decision'){
			return "路由活动";
		}
		if(value=='end'){
			return "结束活动";
		}
		if(value=='sub'){
			return "子流程活动";
		}
		if(value=='auto'){
			return "自由活动";
		}
	}
	
function showWorkitem(activity_instance_id){
	document.forms[0].method = "post";
	document.forms[0].action="${pageContext.request.contextPath}/edu.ccut.saturn.workflow.manager/queryModule/page/workitemList.jsp?activity_instance_id="+activity_instance_id;
	document.forms[0].submit(); 
}

function showActivityInfo(activity_instance_id){
	 var store = new Ext.data.JsonStore({
		    url: "${pageContext.request.contextPath}/edu.ccut.saturn.workflow.manager::/queryModule/action/QueryActivityInfo.action",
		    root: 'result',
		    fields: [
	               {name: 'activity_instance_id', mapping: 'activity_instance_id'},
	               {name: 'name', mapping: 'name'},
		    	   {name: 'description', mapping: 'description'},
	               {name: 'state', mapping: 'state'},
	               {name: 'process_instance_id', mapping: 'process_instance_id'},
	               {name: 'start_time', mapping: 'start_time'},
	               {name: 'end_time', mapping: 'end_time'},
	               {name: 'type', mapping: 'type'},
	               {name: 'is_timeout', mapping: 'is_timeout'},
	               {name: 'timeout_number', mapping: 'timeout_number'}
	           ]
		});
	    store.load({params:{activity_instance_id:activity_instance_id}});
	    
	    store.on('load',function(){
	    var	record = store.getAt(0);
	    var panel = new Ext.FormPanel({
	        frame:true,
	        bodyStyle:'padding:5px 5px 0',
	        items: [{
	            layout:'column',
	            items:[{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '活动ID',
		                    name: 'workitem_id',
		                    id: 'workitem_id',
		                    value:record.data["activity_instance_id"],
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '活动名称',
		                    name: 'name',
		                    id: 'name',
		                    value:record.data["name"],
		                     disabled:true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '活动描述',
		                    name: 'description',
		                    value:record.data["description"],
		                    id: 'description',
		                    disabled :true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '当前状态',
		                    name: 'state',
		                    id: 'state',
		                    value:record.data["state"]=='2'?"运行":"完成",
		                    disabled :true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '流程实例ID',
		                    name: 'process_instacne_id',
		                    id: 'process_instacne_id',
		                    value:record.data["process_instance_id"],
		                    disabled :true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '启动时间',
		                    name: 'start_time',
		                    id: 'start_time',
		                     value:record.data["start_time"],
		                     disabled :true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '活动类型',
		                    name: 'type',
		                    id: 'type',
		                     value:showType(record.data["type"]),
		                      disabled :true
		                },{
		                    xtype:'textfield',
		                    fieldLabel: '结束时间',
		                    name: 'end_time',
		                    id: 'end_time',
		                     value:record.data["end_time"],
		                      disabled :true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '是否超时',
		                    name: 'is_timeout',
		                    id: 'is_timeout',
		                     value:record.data["is_timeout"]=='Y'?"是":"否",
		                      disabled :true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '超时数',
		                    name: 'timeout_number',
		                    id: 'timeout_number',
		                     value:record.data["timeout_number"]=='0'?"":record.data["timeout_number"],
		                     disabled :true
		                }]
	            }] 
        }], buttons: [{
	            text: '返回',
	            handler:function(){
	            	window.close();
	            }
       		 }]
	    });
			
		    var window = new Ext.Window({
				title: '活动实例信息',
				width: 700,
				height:250,
				minWidth: 300,
				minHeight: 200,
				layout: 'fit',
				plain:true,
				items:panel,
				buttonAlign:'center',
				modal:true
			});
			window.show();
	    })              
}

</script>
<div id='form-ct' width='100%'></div>
<div id='process-grid' width='100%'></div>
<form></form>
</head>
</html>